<template>
  <BaseDialog
    ref="baseDialog"
    width="1000px"
    title="设备详情"
    @confrim="confrim"
    @cancel="cancel"
  >
    <div style="margin-bottom: 10px">
      <div>
        <el-button type="primary" @click="init(info)">手动刷新</el-button>
      </div>
      <h2>当前设备：{{ imei }}</h2>
    </div>
    <!-- <div class="item">
      <div>系统版本</div>
      <div>{{ info.osVer }}</div>
    </div> -->
    <!-- <div class="item">
      <div>品牌</div>
      <div>{{ info.brand }}</div>
    </div> -->
    <div v-loading="loading">
      <div class="item">
        <div>型号</div>
        <div style="color: blue">{{ info.model }}</div>
      </div>
      <div class="item">
        <div>显示板温度</div>
        <div>{{ info.baseTemp }}°C</div>
      </div>
      <div class="item">
        <div>灯体温度</div>
        <div>{{ info.lampTemp }}°C</div>
      </div>
      <div class="item">
        <div>启动次数</div>
        <div>{{ info.bootCount }}</div>
      </div>
      <div class="item">
        <div>运行时长</div>
        <div>{{ (info.runTime / 6).toFixed(2) }}</div>
      </div>
      <div class="item">
        <div>亮灯时长</div>
        <div>{{ (info.bulbTime / 6).toFixed(2) }}</div>
      </div>

      <div class="item" v-if="info.errorInfo">
        <div>错误信息</div>
        <div class="detail">
          <!-- {{ info.errorInfo }} -->
          <span :class="{ error: JSON.parse(info.errorInfo).err1.fan1 == 1 }"
            >风机1：{{
              JSON.parse(info.errorInfo).err1.fan1 == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.errorInfo).err1.fan2 == 1 }"
            >风机2：{{
              JSON.parse(info.errorInfo).err1.fan2 == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.errorInfo).err1.power == 1 }"
            >功率：{{
              JSON.parse(info.errorInfo).err1.power == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.errorInfo).err1.uart == 1 }"
            >通讯：{{
              JSON.parse(info.errorInfo).err1.uart == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.errorInfo).err1.temp == 1 }"
            >温度：{{
              JSON.parse(info.errorInfo).err1.temp == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.errorInfo).err1.other == 1 }"
            >其他：{{
              JSON.parse(info.errorInfo).err1.other == 1 ? "出错" : "正常"
            }}</span
          >
        </div>
      </div>
      <div class="item">
        <div>风扇 1 转速</div>
        <div>{{ info.fan1Speed }}</div>
      </div>
      <div class="item">
        <div>风扇 2 转速</div>
        <div>{{ info.fan2Speed }}</div>
      </div>

      <div class="item">
        <div>位置</div>
        <div>{{ info.lng ? info.lng : "暂无位置信息" }}，{{ info.lat }}</div>
      </div>

      <div class="item" v-if="info.resetInfo">
        <div>复位信息</div>
        <div class="detail">
          <span :class="{ error: JSON.parse(info.resetInfo).reset3.xGobo == 1 }"
            >效果盘定位：{{
              JSON.parse(info.resetInfo).reset3.xGobo == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset3.framerot == 1 }"
            >切割器旋转定位：{{
              JSON.parse(info.resetInfo).reset3.framerot == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset3.xGoboR == 1 }"
            >效果盘自转轴定位：{{
              JSON.parse(info.resetInfo).reset3.xGoboR == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset3.tiltOpto == 1 }"
            >Y轴纠错定位：{{
              JSON.parse(info.resetInfo).reset3.tiltOpto == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset3.panOpto == 1 }"
          >
            X轴纠错定位：{{
              JSON.parse(info.resetInfo).reset3.panOpto == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset1.zoom == 1 }">
            放大定位：{{
              JSON.parse(info.resetInfo).reset1.zoom == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset1.pan == 1 }">
            X轴定位：{{
              JSON.parse(info.resetInfo).reset1.pan == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset1.focus == 1 }"
          >
            调焦定位：{{
              JSON.parse(info.resetInfo).reset1.focus == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset1.focus == 1 }"
          >
            图自转定位：{{
              JSON.parse(info.resetInfo).reset1.GoboR == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset1.sGobo == 1 }"
          >
            固图定位：{{
              JSON.parse(info.resetInfo).reset1.sGobo == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset1.color == 1 }"
          >
            色盘定位：{{
              JSON.parse(info.resetInfo).reset1.color == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset1.tilt == 1 }">
            Y轴定位：{{
              JSON.parse(info.resetInfo).reset1.tilt == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset1.rGobo == 1 }"
          >
            旋图定位：{{
              JSON.parse(info.resetInfo).reset1.rGobo == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset2.prism2 == 1 }"
          >
            棱镜2定位：{{
              JSON.parse(info.resetInfo).reset2.prism2 == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset2.CTO == 1 }">
            CTO定位：{{
              JSON.parse(info.resetInfo).reset2.CTO == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset2.Y == 1 }">
            Y色定位：{{
              JSON.parse(info.resetInfo).reset2.Y == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset2.prism1R == 1 }"
          >
            棱1自转轴定位：{{
              JSON.parse(info.resetInfo).reset2.prism1R == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset2.C == 1 }">
            C色定位：{{
              JSON.parse(info.resetInfo).reset2.C == 1 ? "出错" : "正常"
            }}</span
          >
          <span :class="{ error: JSON.parse(info.resetInfo).reset2.M == 1 }">
            M色定位：{{
              JSON.parse(info.resetInfo).reset2.M == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset2.prism1 == 1 }"
          >
            棱镜1定位：{{
              JSON.parse(info.resetInfo).reset2.prism1 == 1 ? "出错" : "正常"
            }}</span
          >
          <span
            :class="{ error: JSON.parse(info.resetInfo).reset2.prism2R == 1 }"
          >
            棱镜2自转轴定位：{{
              JSON.parse(info.resetInfo).reset2.prism2R == 1 ? "出错" : "正常"
            }}</span
          >
        </div>
      </div>
      <div class="item">
        <div>电压</div>
        <div>{{ info.voltage }}</div>
      </div>
      <div class="item">
        <div>X 轴角度</div>
        <div>{{ info.xangle }}</div>
      </div>
      <div class="item">
        <div>Y 轴角度</div>
        <div>{{ info.yangle }}</div>
      </div>
      <div class="item" v-if="row.upgradeVer">
        <div>版本</div>
        <div>
          <el-tag type="primary" size="mini">
            显示板：{{ JSON.parse(row.upgradeVer).ver1 }}</el-tag
          >
          <el-tag type="primary" size="mini">
            XY 轴板：{{ JSON.parse(row.upgradeVer).ver2 }}</el-tag
          >
          <el-tag type="primary" size="mini">
            驱动板A：{{ JSON.parse(row.upgradeVer).ver3 }}</el-tag
          >
          <el-tag type="primary" size="mini">
            驱动板B:{{ JSON.parse(row.upgradeVer).ver4 }}</el-tag
          >
          <el-tag type="primary" size="mini">
            驱动板C:{{ JSON.parse(row.upgradeVer).ver5 }}</el-tag
          >
          <el-tag type="primary" size="mini">
            驱动板D:{{ JSON.parse(row.upgradeVer).ver6 }}</el-tag
          >
        </div>
      </div>
    </div>
  </BaseDialog>
</template>

<script>
import { getDeviceInfo } from "@/api/device";
import { Message } from "element-ui";

export default {
  data() {
    return {
      info: {},
      imei: "",
      loading: false,
      row: {},
      timer: null,
    };
  },
  methods: {
    open(data) {
      this.$refs.baseDialog.open();
      this.init(data);
      this.row = data;
      // this.timer = setInterval(() => {
      // }, 1000);
    },
    async init(data) {
      this.loading = true;
      this.imei = data.imei;

      try {
        const res = await getDeviceInfo({ imei: data.imei });
        if (!res.status) {
          Message.success("获取成功");
          this.info = res.content;
        }
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    },
    confrim() {
      this.$emit("confrim", this.dot);
      this.close();
    },
    close() {
      // clearInterval(this.timer)
      console.log("关闭");
      this.$refs.baseDialog.close();
    },
    cancel() {
      // clearInterval(this.timer)
      console.log("关闭");
    },
  },
};
</script>

<style scoped>
.item {
  display: flex;
  border-bottom: 1px solid #ccc;
  margin-bottom: 5px;
  padding-bottom: 10px;
  div {
    width: 50%;
  }

  .detail {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    span {
      margin-right: 20px;
      border-radius: 8px;
      margin-bottom: 5px;
      padding: 5px;
      background-color: #0073ff;
      color: #fff;
    }
    .error {
      background-color: red;
    }
  }
}
.el-tag {
  margin: 5px;
}
</style>
